CREATE TABLE [Category] (
  [ID] INTEGER NOT NULL ON CONFLICT FAIL PRIMARY KEY ON CONFLICT FAIL AUTOINCREMENT, 
  [ParentID] INT64, 
  [Name] NVARCHAR(512) NOT NULL ON CONFLICT FAIL);


CREATE TABLE [Entity] (
  [ID] INTEGER NOT NULL ON CONFLICT FAIL PRIMARY KEY AUTOINCREMENT, 
  [Content] NVARCHAR(8000) NOT NULL ON CONFLICT FAIL);


CREATE TABLE [EntityCategory] (
  [EID] INTEGER NOT NULL ON CONFLICT FAIL CONSTRAINT [EntityCategory_Entity__Index0] REFERENCES [Entity]([ID]), 
  [CID] INTEGER NOT NULL ON CONFLICT FAIL CONSTRAINT [EntityCategory_Entity__Index1] REFERENCES [category]([ID]), 
  CONSTRAINT [sqlite_autoindex_EntityCategory_1] PRIMARY KEY ([EID], [CID]) ON CONFLICT FAIL);


CREATE TABLE [EntityKey] (
  [EID] INTEGER NOT NULL ON CONFLICT FAIL CONSTRAINT [EntityKey_Entity_Index0] REFERENCES [Entity]([ID]), 
  [KID] INTEGER NOT NULL ON CONFLICT FAIL CONSTRAINT [EntityKey_Key_Index1] REFERENCES [Keys]([ID]), 
  CONSTRAINT [sqlite_autoindex_EntityKey_1] PRIMARY KEY ([KID], [EID]));


CREATE TABLE [Keys] (
  [ID] INTEGER NOT NULL ON CONFLICT FAIL PRIMARY KEY ON CONFLICT FAIL AUTOINCREMENT, 
  [Name] NVARCHAR(512) NOT NULL ON CONFLICT FAIL);


CREATE TABLE [KeysCategory] (
  [KID] INTEGER NOT NULL ON CONFLICT FAIL CONSTRAINT [KeysCategory_Keys__Index0] REFERENCES [Keys]([ID]), 
  [CID] INTEGER NOT NULL ON CONFLICT FAIL CONSTRAINT [KeysCategory_Category__Index1] REFERENCES [Category]([ID]), 
  CONSTRAINT [sqlite_autoindex_KeysCategory_1] PRIMARY KEY ([KID], [CID]) ON CONFLICT FAIL);


CREATE TABLE [Product] (
  [ID] INTEGER NOT NULL ON CONFLICT FAIL PRIMARY KEY AUTOINCREMENT, 
  [Name] NVARCHAR(512) NOT NULL ON CONFLICT FAIL, 
  [Price] DECIMAL NOT NULL ON CONFLICT FAIL DEFAULT 0, 
  [Summary] nvarchar(2048), 
  [Detail] NVARCHAR(8000), 
  [IndexImage] NVARCHAR(512));


CREATE TABLE [ProductCategory] (
  [PID] INTEGER NOT NULL ON CONFLICT FAIL CONSTRAINT [ProductCategory_Product__Index0] REFERENCES [Product]([ID]), 
  [CID] INTEGER NOT NULL ON CONFLICT FAIL CONSTRAINT [ProductCategory_Category__Index1] REFERENCES [Category]([ID]), 
  CONSTRAINT [sqlite_autoindex_ProductCategory_1] PRIMARY KEY ([PID], [CID]) ON CONFLICT FAIL);


CREATE TABLE [ProductImage] (
  [ID] INTEGER NOT NULL ON CONFLICT FAIL PRIMARY KEY AUTOINCREMENT, 
  [PID] INT64 NOT NULL ON CONFLICT FAIL CONSTRAINT [ProductImage_Product_Index0] REFERENCES [Product]([ID]), 
  [ImagePath] NVARCHAR(512) NOT NULL ON CONFLICT FAIL);


CREATE TABLE [ProductKey] (
  [PID] INTEGER NOT NULL ON CONFLICT FAIL CONSTRAINT [ProductKey_Product__Index0] REFERENCES [Product]([ID]), 
  [KID] INTEGER NOT NULL ON CONFLICT FAIL CONSTRAINT [ProductKey_Key_Index1] REFERENCES [Keys]([ID]), 
  CONSTRAINT [sqlite_autoindex_ProductKey_1] PRIMARY KEY ([PID], [KID]) ON CONFLICT FAIL);


